<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能文档RAG应用</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <nav class="navbar">
        <h2>智能文档分析系统</h2>
        <div class="nav-item" onclick="showPage('upload')">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12"/>
            </svg>
            文档上传
        </div>
        <div class="nav-item" onclick="showPage('chat')">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>
            </svg>
            智能问答
        </div>
    </nav>

    <div id="uploadPage" class="container">
        <div class="upload-section">
            <div class="file-upload" onclick="document.getElementById('docUpload').click()">
                <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="var(--primary-color)" stroke-width="2">
                    <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12"/>
                </svg>
                <h3>拖放文件或点击上传</h3>
                <p>支持PDF, DOC, DOCX, PNG, JPG, JPEG, BMP, GIF格式 | 单文档最大限制100MB或1000页，单图片最大限制20MB（同时要求图片短边大于15像素，长边小于8192像素，长宽比小于50）</p>
                <div id="fileNames" class="file-list"></div>
                <input type="file" id="docUpload" accept=".pdf,.doc,.docx,.png,.jpg,.jpeg,.bmp,.gif" class="hidden">
            </div>
            <!-- 新增知识库名称标签 -->
            <div class="kb-name-section">
                <label for="kbNameInput" class="kb-name-label">知识库名称：</label>
                <input type="text" class="kb-name-input" id="kbNameInput" placeholder="例：产品技术文档库">
            </div>
            <button class="submit-btn" onclick="handleUpload()">提交分析</button>
            <div id="uploadProgressContainer" class="progress-bar hidden">
                <div id="uploadProgressBar" class="progress" style="width: 0%;">0%</div>
            </div>
            <div class="analysis-results" id="analysisResults"></div>
        </div>
    </div>

    <div id="chatPage" class="container hidden">
        <div class="chat-container">
            <select class="kb-selector" id="kbSelector">
                <option value="" selected disabled>请选择知识库</option>
            </select>
            <div class="chat-history" id="chatHistory">
                <div class="message bot-message">
                    <div class="message-logo">
                        <img src="/static/AIrobot.svg" width="32" height="32" class="bot-logo">
                    </div>
                    <div class="message-content">您好！请问有什么可以帮助您的？</div>
                </div>
            </div>

            <div class="chat-input">
                <textarea class="chat-textarea" id="chatInput" placeholder="输入您的问题..." rows="3"></textarea>
                <button class="send-btn" onclick="sendMessage()">发送</button>
            </div>
        </div>
    </div>
    <!-- 自定义确认弹窗 -->
    <div id="customConfirm" class="hidden">
        <div class="confirm-overlay"></div>
        <div class="confirm-box">
            <div class="confirm-icon">
                <svg viewBox="0 0 24 24" fill="var(--primary-color)">
                    <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15h2v2h-2v-2zm0-10h2v6h-2V7z"/>
                </svg>
            </div>
            <h3 class="confirm-title">切换知识库</h3>
            <p class="confirm-text">更换知识库将清除当前对话历史，是否继续？</p>
            <div class="confirm-buttons">
                <button class="confirm-btn cancel-btn">取消</button>
                <button class="confirm-btn confirm-btn-primary">继续切换</button>
            </div>
        </div>
    </div>


    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>
